/* eslint-disable */
import { Toast } from "vant";
const BASE_URL = "http://www.pudge.wang:4000";

interface ParamType {
  // eslint-disable-next-line
  [propname: string]: any;
}

const http = {
  get(url: string, params?: ParamType) {
    if (params) {
      const arr: string[] = Object.keys(params);
      const str: string[] = arr.map(
        (item: string) => item + "=" + params[item]
      );
      url += "?" + str.join("&");
    }
    return fetch(BASE_URL + url)
      .then((response) => response.json())
      .then((res) => {
        if (res.status === "0") {
          return res;
        }
      });
  },
  post(url: string, data?: ParamType) {
    return fetch(BASE_URL + url, {
      method: "post",
      headers: {
        "content-type": "application/json",
      },
      body: JSON.stringify(data),
    })
      .then((response) => response.json())
      .then((res) => {
        if (res.status === "0") {
          return res;
        } else {
          Toast.fail(res.msg);
        }
      });
  },
};

export default http;
